﻿using System;
using System.Collections.Generic;
using System.Text;
using Aga.Controls.Tree;
using FlexminAPI;
using System.Drawing;

namespace FlexminAdmin.Tree
{
	internal class ComputerTreeNode : Node
	{
		private IHost host;

		private Dictionary<ComputerState, Image> stateIcons = new Dictionary<ComputerState, Image>();

		public ComputerTreeNode(IHost host)
			: base()
		{
			this.host = host;
			host.StateChanged += new HostUpdateDelegate(host_StateChanged);

			foreach (ComputerState state in Enum.GetValues(typeof(ComputerState)))
			{
				stateIcons[state] = (Image)Properties.Resources.ResourceManager.GetObject("Computer" + state.ToString());
			}
		}

		public IHost Host
		{
			get { return host; }
		}

		void host_StateChanged(IHost sender, HostEventArgs e)
		{
			NotifyModel();
		}

		public override string Text
		{
			get
			{
				return host.HostAddress;
			}
		}

		public override bool IsLeaf
		{
			get
			{
				return true;
			}
		}

		public Image Icon
		{
			get
			{
				return stateIcons[host.State];
			}
		}
	}
}
